<template>
  <div class="supervisionAcceptanceInformation">
    <el-form
      :inline="true"
      ref="projectInfo"
      :model="projectInfo"
      label-width="80px"
      label-position="left"
    >
      <div class="maintitle">项目设计变更咨询（评审）信息</div>
      <el-form-item label="咨询时间">
        <el-date-picker
          :disabled="disabled"
          v-model="projectInfo.consultationTime"
          placeholder="选择时间"
          style="width:200px;"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="复核时间">
        <el-date-picker
          :disabled="disabled"
          v-model="projectInfo.recheckTime"
          value-format="yyyy-MM-dd"
          placeholder="选择时间"
          style="width:200px;"
        ></el-date-picker>
      </el-form-item>
      <div>
        <div>
          <el-form-item label="咨询地点">
            <el-input
              :disabled="disabled"
              style="width:200px;"
              v-model="projectInfo.consultationPlace"
            ></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="咨询组长">
            <el-input
              :disabled="disabled"
              style="width:626%;"
              v-model="projectInfo.consultationLeader"
            ></el-input>
          </el-form-item>
        </div>
      </div>
      <div>
        <el-form-item label="咨询成员">
          <el-input
            :disabled="disabled"
            style="width:626%;"
            v-model="projectInfo.consultationMembers"
          ></el-input>
        </el-form-item>
      </div>
      <el-form-item label="咨询与复核情况" label-width="80px">
        <el-input
          :disabled="disabled"
          class="txtArea"
          type="textarea"
          rows="6"
          style="width:626%;"
          v-model="projectInfo.situation"
        ></el-input>
      </el-form-item>

      <div class="maintitle">附件信息</div>
      <el-form-item label="专家咨询意见书" label-width="120px">
        <el-upload
          v-if="!disabled"
          class="upload-demo"
          :action="uploadUrl"
          :limit="1"
          :on-success="uploadSuccess"
          :file-list="fileList[0]"
          :disabled="disabled"
        >
          <el-button v-if="!disabled" size="small">上传</el-button>
        </el-upload>
        <seeFujianForList
          v-if="disabled && fileList[0]"
          @openPdf="seePdf"
          :file-obj="fileList[0]"
          :file-num="0"
        />
      </el-form-item>
      <div style="margin-top:20px;">
        <el-form-item>
          <el-button v-if="!disabled" :disabled="disabled" type="primary" @click="saveInfo">提交</el-button>
          <el-button v-if="!disabled" @click="getInfo">取消</el-button>
          <el-button v-if="disabled" @click="back">返回</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-dialog :close-on-click-modal="false" :title="pdfName" :visible.sync="pdfFlag" width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth";
import {
  submitAlterationExpertConsultation,
  getProjectNewestAlterationExpertConsultation
} from "@/api/project1/designChange/countyApply/index";
import config from "@/config/index.js";
import seeFujianForList from "@/components/seeFujianForList";

export default {
  components: {
    seeFujianForList
  },
  data() {
    return {
      token: getToken(),
      uploadUrl: config.uploadUrl,
      projectInfo: {
        id: "",
        alterationId: "",
        consultationPlace: "",
        consultationLeader: "",
        consultationMembers: "",
        completionTime: "",
        consultationTime: "",
        recheckTime: "",
        situation: "",
        opinionFileId: "",
        reportFileInfo: null,
        projectId: localStorage.getItem("projectId")
      },
      fileList: [],
      projectId: localStorage.getItem("projectId") || "",
      disabled: true,
      pdfUrl: "",
      pdfFlag: false,
      pdfName: ""
    };
  },

  created() {
    if (this.$route.name === localStorage.getItem("key")) {
      this.disabled = false;
    }
    if (localStorage.getItem("lookStatus") == 2) {
      this.disabled = true;
    }
    console.log(this.$route.name);
    this.getInfo();
  },

  methods: {
    //查看当前PDF
    seePdf(num) {
      this.pdfFlag = true;
      this.pdfUrl = this.fileList[num][0].url;
      this.pdfName = this.fileList[num][0].name;
    },
    // 获取专家咨询信息
    getInfo() {
      getProjectNewestAlterationExpertConsultation({
        projectId: this.projectId
      }).then(res => {
        if (res.code == 1000 && res.data) {
          if (res.data.recheckTime) {
            this.projectInfo.recheckTime = res.data.recheckTime.slice(0, 10);
          }
          if (res.data.consultationTime) {
            this.projectInfo.consultationTime = res.data.consultationTime.slice(
              0,
              10
            );
          }
          if (res.data.id) {
            this.projectInfo.id = res.data.id;
          }
          if (res.data.alterationId) {
            this.projectInfo.alterationId = res.data.alterationId;
          }
          if (res.data.consultationPlace) {
            this.projectInfo.consultationPlace = res.data.consultationPlace;
          }
          if (res.data.consultationLeader) {
            this.projectInfo.consultationLeader = res.data.consultationLeader;
          }
          if (res.data.consultationMembers) {
            this.projectInfo.consultationMembers = res.data.consultationMembers;
          }
          if (res.data.completionTime) {
            this.projectInfo.completionTime = res.data.completionTime;
          }
          if (res.data.situation) {
            this.projectInfo.situation = res.data.situation;
          }
          if (res.data.opinionFileId) {
            this.projectInfo.opinionFileId = res.data.opinionFileId;
          }
          if (res.data.opinionFileInfo) {
            this.projectInfo.opinionFileInfo = res.data.opinionFileInfo;

            let reportFileInfo = this.projectInfo.opinionFileInfo;

            this.projectInfo["opinionFileId"] = reportFileInfo.id;
            this.fileList = [
              [{ name: reportFileInfo.fileName, url: reportFileInfo.filePath }]
            ];
          }
        }
      });
    },
    // 文件上传成功
    uploadSuccess(res, file, fileList) {
      this.projectInfo["opinionFileId"] = res.data.id;
    },

    // 保存数据
    saveInfo() {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      let param = {
        alterationId: this.projectInfo.alterationId,
        projectId: this.projectInfo.projectId,
        consultationPlace: this.projectInfo.consultationPlace,
        consultationLeader: this.projectInfo.consultationLeader,
        consultationMembers: this.projectInfo.consultationMembers,
        completionTime: this.projectInfo.completionTime,
        consultationTime: this.projectInfo.consultationTime + " " + "00:00:00",
        recheckTime: this.projectInfo.recheckTime + " " + "00:00:00",
        opinionFileId: this.projectInfo.opinionFileId
      };

      submitAlterationExpertConsultation(param)
        .then(res => {
          loading.close();
          this.$message({
            message: "提交成功",
            type: "success"
          });
          this.$router.push(
            "/projectManagement/projectImplementation/dealwith"
          );
        })
        .catch(err => {
          loading.close();
        });
    },
    back() {
      this.$router.push("/projectManagement/projectImplementation/dealwith");
    }
  }
};
</script>

<style lang="scss" scoped>
/deep/ .el-form--inline .el-form-item__label {
  color: #a1a1a1;
}

.supervisionAcceptanceInformation {
  padding: 20px 20px 0 20px;
  min-height: calc(100vh - 154px);
  background-color: #fff;
}
</style>
<style lang="scss" scoped>
.maintitle {
  padding: 10px 0 30px 0;
  font-size: 18px;
  font-family: PingFang SC;
  font-weight: bold;
  line-height: 25px;
  color: #4d4d4d;
}
.projected {
  padding: 0 0 30px 0;
  font-size: 15px;
  color: #8c8c8c;
}
.titleDeputy {
  padding: 20px 0 10px 0;
  font-size: 15px;
  color: #8c8c8c;
}
/deep/ .el-form--inline .el-form-item__label {
  color: #8c8c8c;
}
</style>